{extend name="$BASE_LIST" /}
{block name="body"}
<link rel="stylesheet" type="text/css" href="__STATIC__/monthPicker/dateRange.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/monthPicker/monthPicker.css"/>

<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">{$page_nav}</span></div>

    <div id="js_main_header" class="ui-form main_header">

        <div class="left margin-right-5">
            <input style="width:200px" class="form-control" id="month_picker" size="20"/>
        </div>
        <span>
            <select name="level" id="level" class="form-control" style="width:120px">
                <option value="">筛选等级</option>
                <option value="0">普通会员</option>
                {volist name="level_list" id="conf"}
                <option value="{$conf.level}">{$conf.title}</option>
                {/volist}
            </select>
        </span>

        <span>
            <select name="is_frozen" id="is_frozen" class="form-control" style="width:120px">
                <option value="">筛选用户状态</option>
                <option value="0">正常</option>
                <option value="1">冻结</option>
            </select>
        </span>
        <span>
            <select name="is_auth" id="is_auth" class="form-control" style="width:120px">
                <option value="">筛选用户状态</option>
                <option value="0">未认证</option>
                <option value="-1">不通过</option>
                <option value="1">已认证</option>
                <option value="2">待认证</option>
            </select>
        </span>
        <span class="frm_input_box search append">
            <a href="javascript:void(0);" id="js_search" class="frm_input_append">
                <i class="icon wb-search" title="搜索"></i>
            </a>
            <input type="text" id="js_keyword" placeholder="请输入用户名或手机号或邮箱" value="" class="frm_input"/>
        </span>

        <span class="right">
            <button type="button" id="js_addBtn" class="btn btn-primary"><i class="icon wb-plus"></i> 添加用户</button>
        </span>
    </div>
    <table id="grid-table">
        <thead frozen="true">
<!--         <th data-options="field:'head_img',width:100,align:'center',formatter:formatImg">头像</th>-->
        <th data-options="field:'id',width:80,align:'center'">用户ID</th>
        <th data-options="field:'username',width:140,align:'center'">用户名称</th>
        <th data-options="field:'phone',width:140,align:'center'">手机号</th>
<!--        <th data-options="field:'email',width:140,align:'center'">邮箱</th>-->
         <th data-options="field:'level_title',width:80,align:'center'">等级</th>
        <th data-options="field:'invite_code',width:100, align:'center'">邀请码</th>
        </thead>
        <thead>
        <tr>
            <th data-options="field:'to_phone',width:130, align:'center'">推荐人手机号</th>
            <th data-options="field:'to_email',width:130, align:'center'">推荐人邮箱</th>
            <th data-options="field:'is_frozen',width:120,align:'center', formatter:formatStatus">用户状态</th>
             <th data-options="field:'is_auth',width:120,align:'center', formatter:formatAuth">实名认证状态</th>
            <th data-options="field:'register_time',width:150, align:'center'">注册时间</th>
            <th data-options="field:'_oper',halign:'center',formatter: formatOper">操作</th>
        </tr>
        </thead>
    </table>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__STATIC__/monthPicker/dateRange.js"></script>
<script type="text/javascript" src="__STATIC__/monthPicker/monthPicker.js"></script>
<script type="text/javascript">

    var myDate = new Date();
    var month = parseInt(myDate.getMonth()) + 1;
    var toDay = myDate.getFullYear() + '-' + month + '-' + myDate.getDate();
    var dateRange = new pickerDateRange('month_picker', {
        startDate: '2000-01-01',
        endDate: toDay,
        defaultText: ' 至 ',
        theme: 'ta'
    });

    function formatSex(value) {
        if (value == 0) {
            return '女';
        } else {
            return '男';
        }
    }
    $("#js_addBtn").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('add_user');
        openBarWin('添加用户',1000, 500, url, function () {
            reload();
        });
    });
    $("#js_Btn").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('add_ticket');
        openBarWin('一键给票',1000, 500, url, function () {
            reload();
        });
    });
    
    $("#jsAuth").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('user_auth');
        openBarWin('用户认证',1000, 500, url, function () {
            reload();
        });
    });

    function formatImg(value) {
        if (value) {
            var html = '<div class="img_box"><img style="height:35px; margin:5px" src="' + value + '" />  </div>';
        } else {
            var html = '<div class="img_box"><img style="height:35px; margin:5px" src="__IMG__/app.png" />  </div>';
        }
        return html;
    }

    

    function formatVip(value) {
        var text = '';
        if (value==0) {
            text = '普通会员';
        } else {
            console.log(value)
            text = 'VIP'+value;
        }
        return text;
    }


    function formatTVip(value) {
        var text = '';
        if (value==0) {
            text = '普通会员';
        } else if(value==1){
            text = '区县';
        } else if(value==2){
            text = '市';
        } else{
            text = '省';
        }
        return text;
    }


    function formatOper(value, row, index) {
        var html = '<span class="grid-operation">';
        // html += '<button type="button" onclick="look(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-eye"></i>查看</button>';
        html += '<button type="button" onclick="edit(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>编辑资料</button>';

        if(row['is_frozen'] == 0){
            html += '<button type="button" onclick="freeze(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>冻结</button>';
        }else {
            html += '<button type="button" onclick="thaw(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>解冻</button>';
        }
        html += '<button type="button" onclick="network(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>查看推荐</button>';
        // if(row['is_auth'] == 1){
            // html += '<button type="button" onclick="auth_view(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>查看身份证</button>';
        // }
        // html += '<button type="button" onclick="view_childs(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-eye"></i>查看下级网络图</button>';
        html += '<button type="button" onclick="view(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>显示资产</button>';
        // if(row['level']>=5){
        //     html += '<button type="button" onclick="set_area(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>设置代理</button>';
        // }
        // if(row['is_agent']>0){
        //     html += '<button type="button" onclick="cancle_area(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>取消代理</button>';
        // }
        html += '<button type="button" onclick="add_coin_stock(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>拨币</button>';
        // if(row['meid'] != ''){
        //     html += '<button type="button" onclick="unbundling(' + row['id'] + ')" class="btn btn-xs btn-default del-btn"><i class="icon wb-close"></i>解绑</button>';
        // }
        if(row['is_auth'] == 1){
            html += '<button type="button" onclick="auth_view(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>实名认证信息</button>';
        }
        if(row['is_auth'] == 2){
            html += '<button type="button" onclick="auth(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>审核实名认证</button>';
        }
        html += '<button type="button" onclick="del(' + row['id'] + ')" class="btn btn-xs btn-default del-btn"><i class="icon wb-close"></i>删除</button>';
        html += '</span>';
        return html;
    }
    function view_childs(id){
        var url = getURL('view_childs', 'id=' + id);
        window.open(url,"_blank")
    }
    function look(id){
        var url = getURL('look', 'id=' + id);
        title = '查看';
        width = 300;
        height = 300;
        layer.open({
            type: 2,
            title: title,
            area: [width + 'px', height + 'px'],
            maxmin: false,
            //skin: 'layui-layer-rim', //加上边框
            content: url,
        });

    }
    function auth(id) {
        var url = getURL('auth', 'id=' + id);
        openBarWin('认证用户', 1000, 600, url, function () {
            reload();
        }, ['确定','取消']);
    }
    function network(id) {
        var url = getURL('view_childs', 'id=' + id);
        window.open(url,"_blank")
        // window.open('查看团队', url, function () {
        //     reload();
        // }, ['确定', '取消']);
    }
    function auth_view(id){
        var url = getURL('auth_view', 'id=' + id);
        openBarWin('身份证照片', 700, 400, url, function () {
            reload();
        }, ['保存', '取消']);
    }
    function formatStatus(value, row, index) {
        var text = '<span style="color:red">正常</span>';
        if (value == '1')
            text = '<span style="color:green">冻结</span>';
        return text;
    }
    function formatAuth(value, row, index) {
        var text = '<span style="color:red">不通过</span>';
        if (value == 0){
            text = '<span>未认证</span>';
        }else if(value == 1){
            text = '<span style="color:green">已认证</span>';
        }else if(value == 2){
            text = '<span style="color:#0a52ff">待认证</span>';
        }
        return text;
    }
    function formatTalent(value, row, index) {
        var text = '<span style="color:red">普通用户</span>';
        if (value == '1')
            text = '<span style="color:green">一级达人</span>';
        if (value == '2')
            text = '<span style="color:green">二级达人</span>';
        if (value == '3')
            text = '<span style="color:green">三级达人</span>';
        if (value == '4')
            text = '<span style="color:green">四级达人</span>';
        if (value == '5')
            text = '<span style="color:green">五级达人</span>';

        return text;
    }


    $(function () {
        $('#grid-table').datagrid({
            url: getURL('loadList'),
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            singleSelect: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20,
            showFooter:true,
            onLoadSuccess: function(data){
                $('#grid-table').datagrid('reloadFooter', [
                    // {
                    //     username: 'USDT积分统计',
                    //     amount: data.total_usdt
                    // },
                    // {
                    //     username: '元气豆积分统计',
                    //     amount: data.total_bean
                    // },
                    // {
                    //     username: '冻结资产积分统计',
                    //     amount: data.total_freeze
                    // }
                ]);
            }
        });
        //设置分页控件
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10
            pageList: [20, 30, 50]
        });
    });

    function change_frozen(id, status) {
        var title = '确认要解冻此用户吗?';
        if (status == 1)
            title = '确认要冻结此用户吗?';
        confirm(title, function () {
            var url = getURL('change_frozen');
            $.getJSON(url, {id: id, status: status}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    function edit(id) {
        var url = getURL('edit', 'id=' + id);
        openBarWin('编辑', 1000, 700, url, function () {
            reload();
        }, ['确定', '取消']);
    }

    //冻结账号
    function freeze(id) {
            var url = getURL('freeze', 'id=' + id );
            openBarWin('冻结原因', 600, 400, url, function () {
                reload();
            }, ['确定', '取消']);
    }

    //设置转账手续费账号
    function poundage(id, type) {
        if(type == 0){
            var text = '确认要让此账号不需要转账手续费吗？';
        }else {
            var text = '确认要让此账号需要转账手续费吗？';
        }
        confirm(text, function () {
            var url = getURL('poundage');
            $.getJSON(url, {id: id,type:type}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }
    //解冻账号
    function thaw(id) {
        confirm("确认要解冻此账号吗？", function () {
            var url = getURL('thaw');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    //解冻账号
    function cancle_area(id) {
        confirm("确认要取消此账号代理吗?", function () {
            var url = getURL('cancle_area');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    function set_area(id) {
        var url = getURL('set_area', 'id=' + id);
        openBarWin('设置代理', 400, 400, url, function () {
            reload();
        }, ['确定', '取消']);
    }

    function add_coin_stock(id) {
        var url = getURL('add_coin_stock', 'id=' + id);
        openBarWin('用户拨币', 400, 400, url, function () {
            reload();
        }, ['确定', '取消']);
    }

    function usdt_coin_stock(id) {
        var url = getURL('usdt_coin_stock', 'id=' + id);
        openBarWin('USDT拨币', 400, 400, url, function () {
            reload();
        }, ['确定', '取消']);
    }
    function freeze_assets(id) {
        var url = getURL('freeze_assets', 'id=' + id);
        openBarWin('冻结USDT', 400, 400, url, function () {
            reload();
        }, ['确定', '取消']);
    }
    function thaw_assets(id) {
        var url = getURL('thaw_assets', 'id=' + id);
        openBarWin('解冻USDT', 400, 400, url, function () {
            reload();
        }, ['确定', '取消']);
    }
    function view(id){
        var url = getURL('view_balance', 'id=' + id);
        openBarWin('查看资产', 600, 400, url, function () {
            reload();
        }, ['确定', '取消']);
    }
    function del(id) {
        confirm("删除后会员数据无法找回。确认要删除此会员吗？", function () {
            var url = getURL('del');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    $("#js_search").click(function () {
        reload();
    });

    $("#js_expBtn").click(function () {
        location.href = getURL('export');
    });
    $("#talent").change(function () {
        reload();
    });
    $("#is_frozen").change(function () {
        reload();
    });
    $("#is_auth").change(function () {
        reload();
    });
    $("#strength").change(function () {
        reload();
    });
    $("#speed").change(function () {
        reload();
    });
    $("#user_order").change(function () {
        reload();
    });
    $("#level").change(function () {
        reload();
    });
    $("#otc_usdt_power").change(function () {
        reload();
    });
    $("#is_store").change(function () {
        reload();
    });
    $("#vip_level").change(function () {
        reload();
    });
    $("#t_level").change(function () {
        reload();
    });

    function reload() {
        var keyword = $("#js_keyword").val();
        var is_frozen = $("#is_frozen").val();
        var level = $("#level").val();
        var vip_level = $("#vip_level").val();
        var t_level = $("#t_level").val();
        var strength = $("#strength").val();
        var user_order = $("#user_order").val();
        var otc_usdt_power = $("#otc_usdt_power").val();
        var is_store = $("#is_store").val();
        var speed = $("#speed").val();
        var is_auth = $("#is_auth").val();
        var talent = $("#talent").val();
        var month_picker = $("#month_picker").val();
        var arr = month_picker.split(" 至 ");
        var startDate = arr[0];
        var endDate = arr[1];
        $('#grid-table').datagrid('reload', {
            keyword: keyword,
            is_frozen: is_frozen,
            user_order: user_order,
            otc_usdt_power: otc_usdt_power,
            is_store : is_store,
            strength: strength,
            level: level,
            vip_level: vip_level,
            t_level: t_level,
            speed: speed,
            is_auth: is_auth,
            talent: talent,
            startDate: startDate,
            endDate: endDate
        });
    }


</script>
{/block}